package com.example.testautowireimport;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(InjectProperties.class)
@ConditionalOnClass(InjectService.class)
@ConditionalOnProperty(prefix = "inject", name = "enabled", havingValue = "true", matchIfMissing = true)
public class ServiceAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(InjectService.class)
    public InjectService injector(InjectProperties injectProperties) {
        InjectService injectService = new InjectService();
        injectService.setName(injectProperties.getName());
        return injectService;
    }
}
